package day_2022_12_to_3.day;

/**
 * @author haomin
 * @date 2022/12/11 22:40
 **/
public class Day12_11_Review {
    class Solution {
        public int myAtoi(String s) {
            s = s.trim();
            if(s.length() == 0) return 0;
            int i = 0;
            if(s.charAt(i) == '-' || s.charAt(i) == '+') i++;
            long num = 0;
            while(i < s.length() && Character.isDigit(s.charAt(i))) {
                i++;
                num = Long.parseLong(s.substring(0, i));
                if(num >= Integer.MAX_VALUE) return Integer.MAX_VALUE;
                if(num <= Integer.MIN_VALUE) return Integer.MIN_VALUE;
            }
            return (int)num;
        }
    }

    class Solution1 {
        public boolean isPalindrome(int x) {
            StringBuffer sb = new StringBuffer();
            sb.append(x);
            StringBuffer sb2 = new StringBuffer(sb).reverse();
            return sb.toString().equals(sb2.toString());
        }
    }

    class Solution2 {
        public boolean isPalindrome(int x) {
            String s = "";
            s += x;
            int l =0, r = s.length()-1;
            while(l < r) {
                if(s.charAt(l) == s.charAt(r)) {
                    l++; r--;
                }else return false;
            }
            return true;
        }
    }
    class Solution3 {
        public boolean isMatch(String s, String p) {
            if(s.length() < p.length()) return false;
            int i = 0, j = 0;
            char[] sc = s.toCharArray();
            char[] pc = p.toCharArray();
            while(i < sc.length && j < pc.length) {
                if(pc[j] == '.') {
                    if(j+1 < pc.length && pc[j+1] == '*') return true;
                    pc[j] = sc[i];
                    i++; j++;
                }else if(pc[j] == '*') {
                    while(i < sc.length && sc[i] == pc[j-1]) i++;
                    j++;
                }else {
                    if(pc[j] == sc[i]) {
                        i++; j++;
                    } else return false;
                }
            }
            System.out.println(i +" "+j);System.out.println(sc.length +" "+pc.length);
            return i == sc.length && j == pc.length;
        }
    }
}